package com.mayikt.main.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mayikt.common.core.api.BaseApiService;
import com.mayikt.common.core.api.BaseResponse;
import com.mayikt.main.api.UserLoginLogService;
import com.mayikt.main.api.dto.res.UserLoginLogResDto;
import com.mayikt.main.api.impl.entity.SysUserLoginLog;
import com.mayikt.main.api.impl.mapper.SysUserLoginLogMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
public class UserLoginLogImpl extends BaseApiService<List<UserLoginLogResDto>> implements UserLoginLogService {
    @Autowired
    private SysUserLoginLogMapper sysUserLoginLogMapper;

    @Override
    public BaseResponse<List<UserLoginLogResDto>> getUserLoginLog() {
        // 模拟查询登录的日志记录
        List<SysUserLoginLog> sysUserLoginLogs = sysUserLoginLogMapper.selectList(new QueryWrapper<>());
        List<UserLoginLogResDto> userLoginLogResDtos = new ArrayList<>();
        for (int i = 0; i < sysUserLoginLogs.size(); i++) {
            UserLoginLogResDto userLoginLogResDto = new UserLoginLogResDto();
            BeanUtils.copyProperties(sysUserLoginLogs.get(i), userLoginLogResDto);
            userLoginLogResDtos.add(userLoginLogResDto);
        }
        return setResultSuccessData(userLoginLogResDtos);
    }
}